package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.DishFlavor;
import com.sky.enumclass.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;


/**
* @author Morpeko
* @description 针对表【dish(果蔬)】的数据库操作Mapper
* @createDate 2024-08-06 13:20:29
* @Entity com.sky.pojo.Dish
*/
@Mapper
public interface DishMapper{

    Page<DishVO> pageQuery(Dish dish);


    /**
     * @Description: 新增果蔬
     * @Param: [dishDTO]
     * @return: void
     */
    //填充create_time,update_time,create_user,update_user公共字段
    //@AutoFill(operationType = OperationType.INSERT,description = "给新增果蔬的实体类自动填充create_time,update_time,create_user,update_user")
    @AutoFill(operationType = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 查询起售状态的果蔬
     * @param ids
     * @return
     */

    Dish selectOnStatusbyIds(List<Long> ids);

    /**
     * 删除/批量删除果蔬信息
     * @param ids
     */
    void deleteDish(List<Long> ids);

    /**
     * 根据果蔬id查询果蔬信息
     * @param id
     * @return
     */
    DishVO selectDishById(Long id);
    @Select("SELECT id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user FROM dish WHERE category_id = #{categoryId}")
    List<Dish> selectDishByCategoryId(Long categoryId);
    /**
     * 根据果蔬ID设置果蔬状态
     * @param status
     * @param id
     */
    @Update("UPDATE dish SET status = #{status} WHERE id = #{id}")
    void updateStatus(Integer status, Long id);

    /**
     * 根据果蔬ID更新果蔬信息
     * @param updateDish
     */
    @AutoFill(operationType = OperationType.UPDATE,description = "给更新果蔬的实体类自动填充update_time,update_user")
    //@Update("UPDATE dish SET name = #{name}, category_id = #{categoryId}, price = #{price}, image = #{image}, description = #{description}, status = #{status} WHERE id = #{id}")
    void updateDish(Dish updateDish);

    /**
     *
     * 条件查询果蔬列表
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);

    /**
     * 根据条件统计果蔬数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}




